package Operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class Add implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("添加图书");

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入书名:>");
        String name = scanner.nextLine();
        for (int i = 0; i < bookList.NumberBooksExisted; i++) {
            if(name.equals(bookList.books[i].getName())) {
                System.out.println("已经有这本书,不再存放");
                return;
            }
        }

        System.out.println("请输入作者:>");
        String anthor = scanner.nextLine();

        System.out.println("请输入图书类型:>");
        String type = scanner.nextLine();

        System.out.println("请输入价钱:>");
        double price = scanner.nextDouble();

        if(bookList.NumberBooksExisted==bookList.books.length) {
            System.out.println("满了,放不下");
            return;
        }
        Book book = new Book(name,anthor,price,type);

        bookList.books[bookList.NumberBooksExisted++] = book;
    }
}
